home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Dots & Pixels
/
headers
/
stopwatch.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-29
|
1KB
|
68 lines
#pragma once
//
// stopwatch, a class to measure intervals up to about 35 minutes in length with
// a maximal resolution of 20 microseconds (see IM VI, The Time Manager for details)
//
// 'read' and 'stop' return the number of microseconds since 'start' or zero
// if the elapsed time is too great or 'start' wasn't called at all.
// The utility function 'seconds' converts those times into seconds.
//
class stopwatch : public TMTask
{
public:
stopwatch();
~stopwatch();
void start();
long read();
double seconds();
double milliseconds();
double microseconds();
long stop();
static double seconds( long stopwatch_result);
static double milliseconds( long stopwatch_result);
static double microseconds( long stopwatch_result);
private:
static const long starting_value;
int running;
void restart( unsigned long to_go);
};
inline void stopwatch::start()
{
restart( starting_value);
}
inline double stopwatch::seconds()
{
return ((double) read()) / 1000000.0;
}
inline double stopwatch::milliseconds()
{
return ((double) read()) / 1000.0;
}
inline double stopwatch::microseconds()
{
return (double) read();
}
inline double stopwatch::seconds( long stopwatch_result)
{
return ((double) stopwatch_result) / 1000000.0;
}
inline double stopwatch::milliseconds( long stopwatch_result)
{
return ((double) stopwatch_result) / 1000.0;
}
inline double stopwatch::microseconds( long stopwatch_result)
{
return (double) stopwatch_result;
}